package com.china08.yxyapi.api.manage.tec.teaching.scoreport.lequestionanalysis;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.entity.mg.scoreport.report.ExamQuesAnalyse;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.mg.scoreport.ExamQuesAnalyseRepsository;

/**
 * 成绩分析     小题分析
 * 
 */
@CrossOrigin
@RestController
public class LeQuestionAnalysisCheckNameController {
	
	@Autowired
	private ExamQuesAnalyseRepsository examQuesAnalyseRepsository;
	
	@RequestMapping(value = "/api_yw/manage/tec/teaching/scoreport/lequestionanalysis/checkstudent", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public RespModel precess(HttpServletRequest request, HttpServletResponse response,@RequestBody ReqModel reqModel){
		ExamQuesAnalyse examQuesAnalyse = examQuesAnalyseRepsository.findById(reqModel.examQuesAnalyseId);
		List<ExamQuesAnalyse.StudentScore> studentScoreLst = examQuesAnalyse.getStudentScore();
		
		RespModel model = new RespModel();
		
		StudentScore studentScore = null;
		List<StudentScore> studentScore3 = new ArrayList<StudentScore>();
		for (ExamQuesAnalyse.StudentScore studentScore2 : studentScoreLst) {
			studentScore = new StudentScore();
			studentScore.stu_id = studentScore2.stu_id;
			studentScore.stu_nick = studentScore2.stu_nick;
			studentScore.score = studentScore2.score;
			studentScore3.add(studentScore);
		}
		
		int     i, j;  
		  for (i = 0; i < studentScore3.size(); i++)  
		    {  
		        for (j = i + 1; j < studentScore3.size(); j++)  
		        {  
		            if (studentScore3.get(i).score < studentScore3.get(j).score)  
		            {  
		            	StudentScore scoreFenBu = null;
		            	scoreFenBu = studentScore3.get(i);
		            	studentScore3.set(i, studentScore3.get(j));
		            	studentScore3.set(j, scoreFenBu);
		            }  
		        }  
		    } 
		model.studentScore = studentScore3;
        return model;
    }

    protected static class RespModel extends YxyApiRespModel {
    	// 本班级学生,本道题得分. 进行排序存储
    	public List<LeQuestionAnalysisCheckNameController.StudentScore> studentScore;
    }
    protected static class ReqModel extends YxyApiReqModel {
    	//试题id
    	public String examQuesAnalyseId;
    }
    protected class StudentScore {
        public String stu_id;// 学生Id
        public String stu_nick;// 学生名称
        public Double score;// 学生分数
    }
}
